/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaces;

import conexion.Operaciones;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.jvnet.substance.SubstanceLookAndFeel;

/**
 *
 * @author vikko
 */
public class FrameVentaBuscaCliente extends javax.swing.JFrame {
    
    /**
     * Creates new form FrameVentaBuscaCliente
     */
    public FrameVentaBuscaCliente() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        initComponents();        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btn_buscaCliente = new javax.swing.JButton();
        btn_muestraTodos = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla_muestraCliente = new javax.swing.JTable();
        btn_Asignar = new javax.swing.JButton();

        setTitle("Asignar cliente");
        setMaximumSize(new java.awt.Dimension(300, 310));
        setPreferredSize(new java.awt.Dimension(300, 310));
        setResizable(false);

        btn_buscaCliente.setText("Buscar Cliente");
        btn_buscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscaClienteActionPerformed(evt);
            }
        });

        btn_muestraTodos.setText("Mostrar Todos");
        btn_muestraTodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_muestraTodosActionPerformed(evt);
            }
        });

        tabla_muestraCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tabla_muestraCliente.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jScrollPane1.setViewportView(tabla_muestraCliente);

        btn_Asignar.setText("Asignar");
        btn_Asignar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AsignarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btn_Asignar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(btn_buscaCliente)
                        .addGap(18, 18, 18)
                        .addComponent(btn_muestraTodos)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_buscaCliente)
                    .addComponent(btn_muestraTodos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btn_Asignar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void btn_buscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscaClienteActionPerformed
        String cliente= JOptionPane.showInputDialog("Ingresa el Nombre del cliente");
        buscacliente(cliente);
    }//GEN-LAST:event_btn_buscaClienteActionPerformed

    private void btn_muestraTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_muestraTodosActionPerformed
        muestracliente();    
    }//GEN-LAST:event_btn_muestraTodosActionPerformed

    private void btn_AsignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AsignarActionPerformed
     int r= tabla_muestraCliente.getSelectedRow();
     String clave_cliente=(String)tabla_muestraCliente.getValueAt(r, 0);
     System.out.println("Seleccionado: "+clave_cliente);
   //     LogIn log= new LogIn();
    //    String usuario=log.getUsuario();
     //   System.out.println("Usuario: "+usuario);
    }//GEN-LAST:event_btn_AsignarActionPerformed

    
    
     public void buscacliente(String user){
        Operaciones oper= new Operaciones();
       tabla_muestraCliente.setModel(oper.buscaClienteSimple(user));
    }
     
    public void muestracliente(){
       Operaciones oper= new Operaciones();
       tabla_muestraCliente.setModel(oper.consultaTodosClientesSimple());     //
    }
       
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Asignar;
    private javax.swing.JButton btn_buscaCliente;
    private javax.swing.JButton btn_muestraTodos;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabla_muestraCliente;
    // End of variables declaration//GEN-END:variables
}
